;;; init-evil.el --- vim mode -*-lexical-binding:t -*-
;;; Commentary:
;;; Code:

;; vim 按键模拟
(use-package evil
  :defer t
  :init
  (setq evil-want-keybinding nil
	    evil-ex-substitute-global t)
  :config
  (evil-mode 1)
;;; relative line number
  (defun my-enable-relative-line-number ()
    (interactive)
    (display-line-numbers-mode -1)
    (setq display-line-numbers-type 'relative)
    (display-line-numbers-mode 1))

  (defun my-disable-relative-line-number ()
    (interactive)
    (display-line-numbers-mode -1)
    (setq display-line-numbers-type t)
    (display-line-numbers-mode 1))

  (add-hook 'evil-normal-state-entry-hook 'my-enable-relative-line-number)
  (add-hook 'evil-insert-state-entry-hook 'my-disable-relative-line-number)
  (add-hook 'evil-insert-state-exit-hook 'my-enable-relative-line-number))

;; evil-escape vim退出
(use-package evil-escape
  :defer t
  :init(evil-escape-mode 1)
  :bind ("C-g" . evil-escape)
  :config (progn
            (setq-default evil-escape-key-sequence "jk")
            (setq-default evil-escape-delay 0.2)))

;; which-key
(use-package which-key
  :defer t
  :hook (after-init . which-key-mode)
  :config
  (setq
   which-key-popup-type 'minibuffer
   which-key-max-description-length 30
   which-key-show-remaining-keys t)
  (setq which-key-idle-delay 0.1)
  (setq which-key-idle-secondary-delay 0.1)
  )

;; general
(use-package general
  :defer t
  :config
  (general-evil-setup)

  (general-define-key
   :states '(normal visual motion)
   :keymaps 'prog-mode
   "gd" 'xref-find-definitions
   )

  (general-define-key
   :states '(normal visual motion)
   :keymaps 'override
   "gb" 'xref-find-references)

  (general-define-key
   :states '(normal visual motion)
   :keymaps 'override
   "C-o" 'xref-pop-marker-stack)

  (general-create-definer leader-key
    :states '(normal visual motion emacs)
    :prefix "SPC"
    :keymaps 'override
    )
  )

(provide 'init-evil)
;;; init-evil.el ends here
